# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=caddy
pkgver=2.5.2
pkgrel=0
pkgdesc="Fast, multi-platform web server with automatic HTTPS"
url="https://caddyserver.com/"
license="Apache-2.0"
arch="all"
depends="ca-certificates"
makedepends="go libcap"
subpackages="$pkgname-openrc"
pkgusers="$pkgname"
pkggroups="$pkgname"
install="$pkgname.pre-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/caddyserver/caddy/archive/v$pkgver.tar.gz
	$pkgname.initd
	Caddyfile
	"
options="net" # for downloading Go modules

export GOFLAGS="$GOFLAGS -trimpath -mod=readonly -modcacherw"
export GOPATH="$srcdir"
export CGO_ENABLED=0

build() {
	go build -trimpath -ldflags="-s -w" -v -o bin/caddy ./cmd/caddy
}

check() {
	go test ./...
}

package() {
	install -Dm755 bin/caddy "$pkgdir"/usr/sbin/caddy
	setcap cap_net_bind_service=+ep "$pkgdir"/usr/sbin/caddy

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/Caddyfile "$pkgdir"/etc/$pkgname/Caddyfile
}

sha512sums="
98eb10075b6eacd93cfe893f7df6d8d8ce41649b6a6b78937c1ee7ba82ebdf483204d98c5e45501617abfe426d3b12a9a413e49304e1b62569ab3bad489e2c66  caddy-2.5.2.tar.gz
919a7a4158dc38e56aad1ae6e2d65416f7267c03f429738a7d5d9831b34dc5f01a29d69a6d44677dd9bb96c56fee9b0d3dc0f7e4416925f4fe46d34aef88a2d7  caddy.initd
d3110dd79f7d5e602a34d42569104dc97603994e42daf5f6b105303a3d034b52b91ef5fb156d5bf7b7a3a58ec0aeff58afc402618d0555af053771952a866f76  Caddyfile
"
